package com.xveshe.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xveshe.common.annotation.Log;
import com.xveshe.common.core.controller.BaseController;
import com.xveshe.common.core.domain.AjaxResult;
import com.xveshe.common.enums.BusinessType;
import com.xveshe.admin.domain.XsglXslb;
import com.xveshe.admin.service.IXsglXslbService;
import com.xveshe.common.utils.poi.ExcelUtil;
import com.xveshe.common.core.page.TableDataInfo;

/**
 * 学社类别Controller
 *
 * @author 葛亚松
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/admin/xslb")
public class XsglXslbController extends BaseController
{
    @Autowired
    private IXsglXslbService xsglXslbService;

    /**
     * 查询学社类别列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XsglXslb xsglXslb)
    {
        startPage();
        List<XsglXslb> list = xsglXslbService.selectXsglXslbList(xsglXslb);
        return getDataTable(list);
    }

    /**
     * 导出学社类别列表
     */
    @PreAuthorize("@ss.hasPermi('admin:xslb:export')")
    @Log(title = "学社类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsglXslb xsglXslb)
    {
        List<XsglXslb> list = xsglXslbService.selectXsglXslbList(xsglXslb);
        ExcelUtil<XsglXslb> util = new ExcelUtil<XsglXslb>(XsglXslb.class);
        util.exportExcel(response, list, "学社类别数据");
    }

    /**
     * 获取学社类别详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(xsglXslbService.selectXsglXslbById(id));
    }

    /**
     * 新增学社类别
     */
    @PreAuthorize("@ss.hasPermi('admin:xslb:add')")
    @Log(title = "学社类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XsglXslb xsglXslb)
    {
        return toAjax(xsglXslbService.insertXsglXslb(xsglXslb));
    }

    /**
     * 修改学社类别
     */
    @PreAuthorize("@ss.hasPermi('admin:xslb:edit')")
    @Log(title = "学社类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XsglXslb xsglXslb)
    {
        return toAjax(xsglXslbService.updateXsglXslb(xsglXslb));
    }

    /**
     * 删除学社类别
     */
    @PreAuthorize("@ss.hasPermi('admin:xslb:remove')")
    @Log(title = "学社类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        int i = xsglXslbService.deleteXsglXslbByIds(ids);
        if (i > 0)
        return toAjax(i);
        return AjaxResult.error("该分类下存在学社信息，不允许删除！");
    }
}
